/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package skytestarmor;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import ru.jSkyRoom.factory.FinderByFormIdFactory;
import ru.jSkyRoom.factory.LeveledEntryFactory;
import ru.jSkyRoom.finder.FinderByEdidFacade;
import ru.jSkyRoom.finder.FinderByFormId;
import ru.jSkyRoom.interfaces.JSkyMod;
import ru.jSkyRoom.interfaces.major.Armor;
import ru.jSkyRoom.interfaces.major.Enchantment;
import ru.jSkyRoom.interfaces.major.Keyword;
import ru.jSkyRoom.interfaces.major.LeveledItemList;
import ru.jSkyRoom.interfaces.sub.JSkyLeveledEntry;
import ru.jSkyRoom.manager.ModManager;
import ru.jSkyRoom.selector.SelectorFacade;
import skyproc.FormID;

/**
 *
 * @author alx
 */
public class NamesOfEnchments {

    private Map<String, String> keywardEnchNames = new HashMap<String, String>();
    //private Map<KYWD, Map<String, ENCH>> keywordEnchantments = new HashMap<KYWD, Map<String, ENCH>>();
    private HashMap<Keyword, Map<String, recordNameEnchEdID>> keywordEnchantments = new HashMap<>();
    Map<Keyword, Collection<Enchantment>> keywordEnchantmentsLinksIn = new HashMap<>();
    private String[] powerNames = {" I", " II", " III", " IV", " V", " VI"};
    private String[] powerNumb = {"01", "02", "03", "04", "05", "06"};
    private Collection<String> listOfDragonDaedric = new ArrayList<>();
    private Map<String, LeveledItemList> hiehGroupOfleLeveledItems = new HashMap<>();
    private Map<String, LeveledItemList> leveledItemNames = new HashMap<>();//SublistEnchArmor_Valkyrie_Gloves_04
    private int[] lvlArray = {1, 9, 17, 25, 37, 43};
    /*
     public NamesOfEnchments(Mod patc) {
     fullkeywordEnchantments(keywordEnchantmentsLinksIn);
     }
     */

    public NamesOfEnchments(Map<Keyword, Collection<Enchantment>> keywordEnchantmentsLinks, JSkyMod patc) {
        fullkeywordEnchantments(keywordEnchantmentsLinks);
        fullHiehGroupOfleLeveledItems(patc);
        listOfDragonDaedric.add("Dragon");

        for (LeveledItemList leveled : SelectorFacade.create(patc).selectLeveledItemLists()) {
            if (leveled.getEDID().startsWith("LBenchArmorS_") && leveled.getEDID().startsWith("LBenchClothS_")) {
                leveledItemNames.put(leveled.getEDID(), leveled);
                getActiveMod().addMajor(leveled);
            }
        }

        FormID ClothingNecklaceFID = getFinder().findKeyword("ClothingNecklace").getForm();
        FormID ClothingRingFID = getFinder().findKeyword("ClothingRing").getForm();
        FormID ArmorBootsFID = getFinder().findKeyword("ArmorBoots").getForm();
        FormID ClothingFeetFID = getFinder().findKeyword("ClothingFeet").getForm();
        FormID ArmorCuirassFID = getFinder().findKeyword("ArmorCuirass").getForm();
        FormID ClothingBodyFID = getFinder().findKeyword("ClothingBody").getForm();
        FormID ArmorGauntletsFID = getFinder().findKeyword("ArmorGauntlets").getForm();
        FormID ClothingHandsFID = getFinder().findKeyword("ClothingHands").getForm();
        FormID ArmorHelmetFID = getFinder().findKeyword("ArmorHelmet").getForm();
        FormID ClothingHeadFID = getFinder().findKeyword("ClothingHead").getForm();
        FormID ClothingCircletFID = getFinder().findKeyword("ClothingCirclet").getForm();
        FormID ArmorShieldFID = getFinder().findKeyword("ArmorShield").getForm();
        FormID ArmorHeavyFID = getFinder().findKeyword("ArmorHeavy").getForm();
        FormID ArmorLightFID = getFinder().findKeyword("ArmorLight").getForm();

    }

    private void fullHiehGroupOfleLeveledItems(JSkyMod patc) {

        ArrayList<String> listOfTypeArmorsGroup = new ArrayList<>();
        listOfTypeArmorsGroup.add("LItemEnchArmorHeavyBoots");
        listOfTypeArmorsGroup.add("LItemEnchArmorHeavyCuirass");
        listOfTypeArmorsGroup.add("LItemEnchArmorHeavyGauntlets");
        listOfTypeArmorsGroup.add("LItemEnchArmorHeavyHelmet");
        listOfTypeArmorsGroup.add("LItemEnchArmorHeavyShield");
        listOfTypeArmorsGroup.add("LItemEnchArmorLightBoots");
        listOfTypeArmorsGroup.add("LItemEnchArmorLightCuirass");
        listOfTypeArmorsGroup.add("LItemEnchArmorLightGauntlets");
        listOfTypeArmorsGroup.add("LItemEnchArmorLightHelmet");
        listOfTypeArmorsGroup.add("LItemEnchArmorLightShield");

        ArrayList<String> listOfTypeClothingGroup = new ArrayList<>();
        listOfTypeClothingGroup.add("RobesAlteration");
        listOfTypeClothingGroup.add("RobesConjuration");
        listOfTypeClothingGroup.add("RobesDestruction");
        listOfTypeClothingGroup.add("RobesIllusion");
        listOfTypeClothingGroup.add("RobesRestoration");
        String[] allTypeEnchments = {"Alchemy", "Alteration", "Archery", "Block", "Carry", "Conjuration", "Destruction", "Health", "HealthRegen", "HeavyArmor",
            "Illusion", "LightArmor", "Lockpicking", "Magicka", "MagickaRegen", "Muffle", "OneHanded", "Pickpocket", "ResistDisease", "ResistFire", "ResistFrost", "ResistMagic",
            "ResistPoison", "ResistShock", "Restoration", "Robes", "Smithing", "Sneak", "Speechcraft", "Stamina", "StaminaRegen", "TwoHanded", "UnarmedDamage", "Waterbreathing"};
        String[] allRingEnchments = {"Alchemy", "Alteration", "Archery", "Block", "Carry", "Conjuration", "Destruction", "Health", "HealthRegen", "HeavyArmor",
            "Illusion", "LightArmor", "Lockpicking", "Magicka", "MagickaRegen", "OneHanded", "Pickpocket", "ResistDisease", "ResistFire", "ResistFrost", "ResistMagic",
            "ResistPoison", "ResistShock", "Restoration", "Smithing", "Sneak", "Stamina", "TwoHanded", "UnarmedDamage", "Waterbreathing"};

        String[] allNecklaceEnchments = {"Alchemy", "Block", "Health", "HeavyArmor",
            "LightArmor", "Lockpicking", "Magicka", "OneHanded", "Pickpocket", "ResistFire", "ResistFrost", "ResistMagic",
            "ResistShock", "Smithing", "Sneak", "Speechcraft", "Stamina", "TwoHanded"};
        for (String enchName : allNecklaceEnchments) {
            listOfTypeClothingGroup.add("EnchNecklace" + enchName);
        }
        String[] allCircletEnchments = {"Alchemy", "Alteration", "Conjuration", "Destruction",
            "Illusion", "Magicka", "Restoration", "Marksman"};
        for (String enchName : allCircletEnchments) {
            listOfTypeClothingGroup.add("EnchCirclet" + enchName);
        }

        Map<String, LeveledItemList> lastGroupOfLeveledItems = getLastGroupOfLeveledItems(patc, listOfTypeArmorsGroup, listOfTypeClothingGroup);//LItemEnchArmorLightBootsNoDragon_LB_KR  ***** All from Kepper_Radiant.esp

        LeveledItemList leveledItems;
        LeveledItemList leveledItemsDragon;
        LeveledItemList tmpLVLI;
        String nameLeveledItems;
        for (String typeArmorsGroup : listOfTypeArmorsGroup) {
            for (int i = 1; i < 7; i++) {
                nameLeveledItems = typeArmorsGroup + "_LB_z0" + String.valueOf(i);  //LItemEnchArmorLightBoots_LB_z01
                //nameLeveledItems = "LB_"+typeArmorsGroup + "_z0" + String.valueOf(i);  //LItemEnchArmorLightBoots_LB_z01
                leveledItems = getFinder().findLeveledItemList(nameLeveledItems);
                if (leveledItems == null) {
                    LeveledItemList base = getFinder().findLeveledItemList("LItem_LB__Gloves");
                    leveledItems = getActiveMod().makeCopy(base, nameLeveledItems);
                    //tmpLVLI =lastGroupOfLeveledItems.get(typeArmorsGroup + "_LB_KR");
                    JSkyLeveledEntry leveledEntry = getLeveledEntryFactory().create(leveledItems, lvlArray[i - 1], 1);
                    lastGroupOfLeveledItems.get(typeArmorsGroup + "_LB_KR").addEntry(leveledEntry);
                    //tmpLVLI =lastGroupOfLeveledItems.get(typeArmorsGroup + "Special_LB_KR");
                    lastGroupOfLeveledItems.get(typeArmorsGroup + "Special_LB_KR").addEntry(leveledEntry);

                } else {
                    getActiveMod().addMajor(leveledItems);
                }
                hiehGroupOfleLeveledItems.put(leveledItems.getEDID(), leveledItems);

                nameLeveledItems = typeArmorsGroup + "NoDragon_LB_z0" + String.valueOf(i);//LItemEnchArmorLightBootsNoDragon_LB_z01
                //nameLeveledItems = "LB_"+typeArmorsGroup + "NoDragon_z0" + String.valueOf(i);//LItemEnchArmorLightBootsNoDragon_LB_z01
                leveledItems = getFinder().findLeveledItemList(nameLeveledItems);
                if (leveledItems == null) {
                    LeveledItemList base = getFinder().findLeveledItemList("LItem_LB__Gloves");
                    leveledItems = getActiveMod().makeCopy(base, nameLeveledItems);
                    JSkyLeveledEntry leveledEntry = getLeveledEntryFactory().create(leveledItems, lvlArray[i - 1], 1);
                    lastGroupOfLeveledItems.get(typeArmorsGroup + "NoDragon_LB_KR").addEntry(leveledEntry);
                } else {
                    getActiveMod().addMajor(leveledItems);
                }
                hiehGroupOfleLeveledItems.put(leveledItems.getEDID(), leveledItems);
            }
        }

        //LBench_RobesAlteration_03
        /*
         LBench_RobesAlteration_03 <----
         LItemRobesAlteration_LB_KR
         */
        for (String typeClothingGroup : listOfTypeClothingGroup) {
            for (int i = 1; i < 7; i++) {
                if (typeClothingGroup.startsWith("Ench")) {
                    nameLeveledItems = "LBench_" + typeClothingGroup.substring(4) + "_0" + String.valueOf(i);  // LBench_RobesAlteration_03
                } else {
                    nameLeveledItems = "LBench_" + typeClothingGroup + "_0" + String.valueOf(i);  // LBench_RobesAlteration_03

                }

                leveledItems = getFinder().findLeveledItemList(nameLeveledItems);
                if (leveledItems == null) {
                    LeveledItemList base = getFinder().findLeveledItemList("LItem_LB__Gloves");
                    leveledItems = getActiveMod().makeCopy(base, nameLeveledItems);

                    tmpLVLI = lastGroupOfLeveledItems.get("LItem" + typeClothingGroup + "_LB_KR");
                    if (tmpLVLI == null) {
                        tmpLVLI = null;
                    } else {
                        JSkyLeveledEntry leveledEntry = getLeveledEntryFactory().create(leveledItems, lvlArray[i - 1], 1);
                        lastGroupOfLeveledItems.get("LItem" + typeClothingGroup + "_LB_KR").addEntry(leveledEntry);
                    }
                }
                hiehGroupOfleLeveledItems.put(leveledItems.getEDID(), leveledItems);

            }
        }

        for (LeveledItemList lastLVLI
                : lastGroupOfLeveledItems.values()) {
            getActiveMod().addMajor(lastLVLI);
        }
    }

    private Map<String, LeveledItemList> getLastGroupOfLeveledItems(JSkyMod patc, Collection<String> listOfTypeArmorsGroup, Collection<String> listOfTypeClothingGroup) {
        Map<String, LeveledItemList> lastGroupOfLeveledItems = new HashMap<>();

        FileWriter txtFile2;
        try {
            //txtFile2 = new FileWriter("C:\\Steam\\SteamApps\\common\\Skyrim\\Data\\Test.txt");
            //PrintWriter txtPrint2 = new PrintWriter(txtFile2);

            for (String nameOfGroup : listOfTypeArmorsGroup) {
                //fullTripleksOfLastGroupOfLeveledItems(lastGroupOfLeveledItems, patc, nameOfGroup, txtPrint2);
                fullTripleksOfLastGroupOfLeveledItems(lastGroupOfLeveledItems, patc, nameOfGroup);
            }

            for (String nameOfGroup : listOfTypeClothingGroup) {
                LeveledItemList leveledItemList = getFinder().findLeveledItemList("LItem" + nameOfGroup + "_LB_KR");
                lastGroupOfLeveledItems.put("LItem" + nameOfGroup + "_LB_KR", leveledItemList);
                //txtPrint2.println(nameOfGroup + "_LB_KR");
            }

            //txtFile2.close();
            //} catch (IOException ex) {
        } catch (Exception ex) {
            Logger.getLogger(NamesOfEnchments.class
                    .getName()).log(Level.SEVERE, null, ex);
        }
        return lastGroupOfLeveledItems;
    }

    private void fullTripleksOfLastGroupOfLeveledItems(Map<String, LeveledItemList> lastGroupOfLeveledItems, JSkyMod patc, String nameOfGroup) {
        LeveledItemList leveledItemList_LB_KR = getFinder().findLeveledItemList(nameOfGroup + "_LB_KR");
        LeveledItemList leveledItemList_NoDragon_LB_KR = getFinder().findLeveledItemList(nameOfGroup + "NoDragon_LB_KR");
        LeveledItemList leveledItemList_Special_LB_KR = getFinder().findLeveledItemList(nameOfGroup + "Special_LB_KR");
        lastGroupOfLeveledItems.put(nameOfGroup + "_LB_KR", leveledItemList_LB_KR);
        lastGroupOfLeveledItems.put(nameOfGroup + "NoDragon_LB_KR", leveledItemList_NoDragon_LB_KR);
        lastGroupOfLeveledItems.put(nameOfGroup + "Special_LB_KR", leveledItemList_Special_LB_KR);

        //txtPrint2.println(nameOfGroup + "_LB_KR");
        //txtPrint2.println(nameOfGroup + "NoDragon_LB_KR");
        //txtPrint2.println(nameOfGroup + "Special_LB_KR");
    }

    private void fullkeywordEnchantments(Map<Keyword, Collection<Enchantment>> keywordEnchantmentsLinks) {
        recordNameEnchEdID record;
        generateNamesOfEnchments();

        boolean isRobe;
        for (Keyword keyword : keywordEnchantmentsLinks.keySet()) {
            Map<String, recordNameEnchEdID> enchRecords = new HashMap<>();
            if (keyword.getEDID().equals("ClothingBody")) {
                isRobe = true;
            } else {
                isRobe = false;
            }

            for (Enchantment enchment : keywordEnchantmentsLinks.get(keyword)) {
                record = new recordNameEnchEdID();
                String edIDname = enchment.getEDID();
                String enchTip = getTipFromEditID(edIDname);

                if (isRobe) {
                    record.edIDname = enchTip.substring(0, enchTip.length() - 2) + "R" + enchTip.substring(enchTip.length() - 2);
                } else {
                    record.edIDname = enchTip;
                }
                record.enchmentFID = enchment.getForm();
                record.name = keywardEnchNames.get(enchTip);

                enchRecords.put(enchTip, record);
            }

            keywordEnchantments.put(keyword, enchRecords);
        }

    }

    public void createEnchmentArmors(Armor armor, JSkyMod patc) {
        //armor.getKeywordSet()
        Keyword armorLight = getFinder().findKeyword("ArmorLight");
        Keyword armorHeavy = getFinder().findKeyword("ArmorHeavy");
        Boolean isLightArmor = armor.getKeywords().contains(armorLight);
        Boolean isHeavyArmor = armor.getKeywords().contains(armorHeavy);
        ArrayList<Armor> armorList = new ArrayList<>();

        keywordEnchantments.containsKey(this);
        for (Keyword keywordFID : armor.getKeywords()) {
            if (keywordEnchantments.containsKey(keywordFID)) {
                Map<String, recordNameEnchEdID> nameEnchMap = keywordEnchantments.get(keywordFID);
                for (String key : nameEnchMap.keySet()) {
                    if (key.contains("LightArmor") || key.contains("HeavyArmor")) {
                        if (key.contains("LightArmor") && !isLightArmor) {
                            continue;
                        }
                        if (key.contains("HeavyArmor") && !isHeavyArmor) {
                            continue;
                        }
                    }

                    try {
                        recordNameEnchEdID enchRecord = nameEnchMap.get(key);
                        String newEnchArmorName = "LBench_" + armor.getEDID().substring(3) + "_" + enchRecord.edIDname;
                        Armor newEnchArmor = getFinder().findArmor(newEnchArmorName);
                        if (newEnchArmor == null) {

                            newEnchArmor = getActiveMod().makeCopy(armor, newEnchArmorName);
                            Enchantment enchantment = getEntchantmentByFormIdFinder().find(enchRecord.enchmentFID);
                            newEnchArmor.setEnchantment(enchantment);
                            if (enchRecord.name != null) {
                                //String newName = armor.getName() + " " + new String(enchRecord.name.getBytes(), "KOUI-8R");
                                //String newName = armor.getName() + " " + new String(enchRecord.name.getBytes(), "windows-1251");
                                //String newName = armor.getName() + " " + enchRecord.name;
                                String newName = armor.getName() + " " + new String(enchRecord.name.getBytes("windows-1251"), "windows-1252");
                                newEnchArmor.setName(newName);
                                newEnchArmor.setTemplate(armor);

                            }

                        }
                        armorList.add(newEnchArmor);

                    } catch (UnsupportedEncodingException ex) {
                        Logger.getLogger(NamesOfEnchments.class
                                .getName()).log(Level.SEVERE, null, ex);
                    }

                }
            }
        }

        creteLeveledItemsListStructute(patc, armorList);
    }

    public void saveToFile(JSkyMod libMods) {
        FileWriter txtFile2;
        PrintWriter txtPrint2;

        for (Keyword keyword : keywordEnchantments.keySet()) {

            try {
                txtFile2 = new FileWriter(".\\Enchantments\\" + keyword.getEDID() + ".txt");
                txtPrint2 = new PrintWriter(txtFile2);

                Map<String, recordNameEnchEdID> enchantmentsList = keywordEnchantments.get(keyword.getForm());
                for (recordNameEnchEdID record : enchantmentsList.values()) {
                    txtPrint2.println(record.edIDname);

                }
            } catch (IOException ex) {
                Logger.getLogger(NamesOfEnchments.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }

    public void createEnchmentArmorByKeyword(Armor armor, JSkyMod patc, Keyword keword) {
        //armor.getKeywordSet()

        Keyword armorLight = getFinder().findKeyword("ArmorLight");
        Keyword armorHeavy = getFinder().findKeyword("ArmorHeavy");
        Boolean isLightArmor = armor.getKeywords().contains(armorLight);
        Boolean isHeavyArmor = armor.getKeywords().contains(armorHeavy);

        Collection<Armor> armorList = new ArrayList<>();

        keywordEnchantments.containsKey(this);
        if (keywordEnchantments.containsKey(keword.getForm())) {
            Map<String, recordNameEnchEdID> nameEnchMap = keywordEnchantments.get(keword.getForm());
            for (String key : nameEnchMap.keySet()) {
                if (key.contains("LightArmor") || key.contains("HeavyArmor")) {
                    if (key.contains("LightArmor") && !isLightArmor) {
                        continue;
                    }
                    if (key.contains("HeavyArmor") && !isHeavyArmor) {
                        continue;
                    }
                }

                try {
                    recordNameEnchEdID enchRecord = nameEnchMap.get(key);
                    String newEnchArmorName = "LBench_" + armor.getEDID().substring(3) + "_" + enchRecord.edIDname;
                    Armor newEnchArmor = getFinder().findArmor(newEnchArmorName);
                    if (newEnchArmor == null) {

                        newEnchArmor = getActiveMod().makeCopy(armor, newEnchArmorName);
                        Enchantment enchantment = getEntchantmentByFormIdFinder().find(enchRecord.enchmentFID);
                        newEnchArmor.setEnchantment(enchantment);
                        if (enchRecord.name != null) {
                            //String newName = armor.getName() + " " + new String(enchRecord.name.getBytes(), "KOUI-8R");
                            //String newName = armor.getName() + " " + new String(enchRecord.name.getBytes(), "windows-1251");
                            String newName = armor.getName() + " " + new String(enchRecord.name.getBytes("windows-1251"), "windows-1252");
                            //String newName = armor.getName() + " " + enchRecord.name;
                            newEnchArmor.setName(newName);
                            newEnchArmor.setTemplate(armor);

                        }

                    }
                    armorList.add(newEnchArmor);

                } catch (UnsupportedEncodingException ex) {
                    Logger.getLogger(NamesOfEnchments.class
                            .getName()).log(Level.SEVERE, null, ex);
                }

            }
        }

        creteLeveledItemsListStructute(patc, armorList);
    }

    private void creteLeveledItemsListStructute(JSkyMod patc, Collection<Armor> armorList) {
        /*
         LBench_Valkyrie_Gloves_Alchemy04  - item
         LBenchArmorS_Valkyrie_Gloves_04 <----
         LItemEnchArmorLightGauntlets_LB_z04  <----
         LItemEnchArmorLightGauntlets_LB_KR
         LItemEnchArmorLightGauntlets
         *
         LBench_Frostbite_Cuirass_AlterationR03  - item
         LBench_RobesAlteration_03 <----
         LItemRobesAlteration_LB_KR
         LItemRobesAlteration
         *
         LBench_Chaos_Amulet_Block03  - item
         LBench_NecklaceBlock_03 <----    LBench_Chaos_Amulet_03  <----
         LItemEnchNecklaceBlock_LB_KR
         LItemEnchNecklaceBlock
         */

        LeveledItemList curLeveledItem;
        String newLvlItemName;

        for (Armor armor : armorList) {
            String str = armor.getEDID(); //LBench_Valkyrie_Gloves_Alchemy04
            String name = str.substring(7, str.lastIndexOf("_"));//Valkyrie_Gloves
            String nameOfSet = name.substring(0, name.lastIndexOf("_"));//Valkyrie
            TypeArmor typeArmor = new TypeArmor(armor, patc, listOfDragonDaedric);//LightGloves
//            hhj
            if (typeArmor.isArmor()) {
                /*
                 LBench_Valkyrie_Gloves_Alchemy04 - item
                 LBenchArmorS_Valkyrie_Gloves_04 <----
                 LItemEnchArmorLightGauntlets(/NoDragon)_LB_z04  <----
                 LItemEnchArmorLightGauntlets_LB_KR
                 LItemEnchArmorLightGauntlets
                 */
                newLvlItemName = "LBenchArmorS_" + name + "_" + typeArmor.getLvl();//LBenchArmorS_Valkyrie_Gloves_04

                if (leveledItemNames.containsKey(newLvlItemName)) {
                    curLeveledItem = leveledItemNames.get(newLvlItemName);
                } else {
                    LeveledItemList base = getFinder().findLeveledItemList("LItem_LB__Gloves");
                    curLeveledItem = getActiveMod().makeCopy(base, newLvlItemName);
                    leveledItemNames.put(newLvlItemName, curLeveledItem);
                }
                JSkyLeveledEntry leveledEntry = getLeveledEntryFactory().create(armor, 1, 1);
                curLeveledItem.addEntry(leveledEntry);

                for (String nameOfHiehGroup : typeArmor.getArNameHiehGroupOfLeveledItems()) {
                    if (hiehGroupOfleLeveledItems.get(nameOfHiehGroup) != null) {
                        JSkyLeveledEntry curLeveledEntry = getLeveledEntryFactory().create(curLeveledItem, 1, 1);
                        hiehGroupOfleLeveledItems.get(nameOfHiehGroup).addEntry(curLeveledEntry);
                    }
                }

            } else {
                /*
                 LBench_Frostbite_Cuirass_AlterationR03  - item
                 LBench_RobesAlteration_03 <----
                 LItemRobesAlteration_LB_KR
                 LItemRobesAlteration
                 *
                 LBench_Chaos_Amulet_Block03  - item
                 LBench_NecklaceBlock_03 <----    LBench_Chaos_Amulet_03  <----
                 LItemEnchNecklaceBlock_LB_KR
                 LItemEnchNecklaceBlock
                 */
                JSkyLeveledEntry leveledEntry;
                //if (typeArmor.isRobes()) {
                newLvlItemName = "LBenchArmorS_" + name + "_" + typeArmor.getLvl();//LBenchArmorS_Valkyrie_Gloves_04
                //newLvlItemName = "LBenchRobeS_" + name + "_" + typeArmor.getLvl();//LBenchArmorS_Valkyrie_Gloves_04
                LeveledItemList enchItemGroup = getFinder().findLeveledItemList(newLvlItemName);
                if (enchItemGroup == null) {
                    LeveledItemList base = getFinder().findLeveledItemList("LItem_LB__Gloves");
                    enchItemGroup = getActiveMod().makeCopy(base, newLvlItemName);
                }
                leveledEntry = getLeveledEntryFactory().create(armor, 1, 1);
                enchItemGroup.addEntry(leveledEntry);
                //}

                for (String nameOfHiehGroup : typeArmor.getArNameHiehGroupOfLeveledItems()) {
                    if (hiehGroupOfleLeveledItems.get(nameOfHiehGroup) != null) {
                        leveledEntry = getLeveledEntryFactory().create(armor, 1, 1);
                        hiehGroupOfleLeveledItems.get(nameOfHiehGroup).addEntry(leveledEntry);
                    }
                }

            }

        }
    }

    private void generateNamesOfEnchments3() {

        full6("Alchemy", "Alchemy");
        full6("Alteration", "Alteration");
        full6("Block", "Block");
        full36("HealRate", "HealRate");
        full6("Carry", "Carry");
        full6("Conjuration", "Conjuration");
        full6("Destruction", "Destruction");
        full6("HealRate", "HealRate");
        full6("Health", "Health");
        full6("HeavyArmor", "HeavyArmor");
        full6("Illusion", "Illusion");
        full6("LightArmor", "LightArmor");
        full6("Lockpicking", "Lockpicking");
        full6("Magicka", "Magicka");
        full36("MagickaRate", "MagickaRate");
        full6("Marksman", "Marksman");
        full6("OneHanded", "OneHanded");
        full6("Pickpocket", "Pickpocket");
        full6("Restoration", "Restoration");
        full6("Smithing", "Smithing");
        full6("Sneak", "Sneak");
        full6("Speechcraft", "Speechcraft");
        full6("Stamina", "Stamina");
        full36("StaminaRate", "StaminaRate");
        full6("TwoHanded", "TwoHanded");
        //full6("Muffle", "");
        keywardEnchNames.put("Muffle", "Muffle");
        keywardEnchNames.put("ResistDisease01", "ResistDisease01");
        keywardEnchNames.put("ResistDisease02", "ResistDisease02");
        keywardEnchNames.put("ResistPoison01", "ResistPoison01");
        keywardEnchNames.put("ResistPoison02", "ResistPoison02");
        keywardEnchNames.put("Waterbreathing", "Waterbreathing");
        full6("ResistFire", "ResistFire");
        full6("ResistFrost", "ResistFrost");
        full6("ResistMagic", "ResistMagic");
        full6("ResistShock", "ResistShock");
    }

    public void generateNamesOfEnchments() {

        full6("Alchemy", "алхимика");
        full6("Alteration", "изменения");
        full6("Block", "блокирования");
        //full36("HealRate", "регенерации");
        full6("HealRate", "регенерации");
        full6("Carry", "носильщика");
        full6("Conjuration", "колдовства");
        full6("Destruction", "разрушения");
        full6("HealRate", "регенерации");
        full6("Health", "здоровья");
        full6("HeavyArmor", "латника");
        full6("Illusion", "иллюзий");
        full6("LightArmor", "застрельщика");
        full6("Lockpicking", "взлома");
        full6("Magicka", "маны");
        full6("MagickaRate", "перезарядки");
        //full36("MagickaRate", "перезарядки");
        full6("Marksman", "лучника");
        full6("OneHanded", "дуэлянта");
        full6("Pickpocket", "карманника");
        full6("Restoration", "восстановления");
        full6("Smithing", "кузнеца");
        full6("Sneak", "скрытности");
        full6("Speechcraft", "оратора");
        full6("Stamina", "запаса сил");
        //full36("StaminaRate", "неутомимости");
        full6("StaminaRate", "неутомимости");
        full6("TwoHanded", "варвара");
        //full6("Muffle", "");
        keywardEnchNames.put("Muffle", "тишины");
        keywardEnchNames.put("ResistDisease01", "сопротивление к болезням");
        keywardEnchNames.put("ResistDisease02", "иммунитет к болезням");
        keywardEnchNames.put("ResistPoison01", "сопротивление к яду");
        keywardEnchNames.put("ResistPoison02", "иммунитет к яду");
        keywardEnchNames.put("Waterbreathing", "ныряльщика");
        full6("ResistFire", "прохлады");
        full6("ResistFrost", "тепла");
        full6("ResistMagic", "антимагии");
        full6("ResistShock", "заземления");
    }

    private void full6(String enchName, String name) {
        for (int i = 0; i < 6; i++) {
            keywardEnchNames.put(enchName + powerNumb[i], name + powerNames[i]);
        }
    }

    private void full36(String enchName, String name) {
        for (int i = 3; i < 6; i++) {
            keywardEnchNames.put(enchName + powerNumb[i], name + powerNames[i]);
        }
    }

    private String getTipFromEditID(String editID) {
        int l_EnchRobesFortify = "EnchRobesFortify".length();
        int l_EnchArmorFortify = "EnchArmorFortify".length();
        int l_EnchArmorResist = "EnchArmor".length();
        int l_EnchArmor = "EnchArmor".length();

        String enchTip = "";

        if (editID.startsWith("EnchRobesFortify") && !editID.endsWith("Base")) {
            enchTip = editID.substring(l_EnchRobesFortify);
        } else if (editID.startsWith("EnchArmor") && !editID.endsWith("Base")) {
            if (editID.startsWith("EnchArmorFortify")) {
                enchTip = editID.substring(l_EnchArmorFortify);
            } else if (editID.startsWith("EnchArmorResist")) {
                enchTip = editID.substring(l_EnchArmorResist);
            } else {
                enchTip = editID.substring(l_EnchArmor);
            }
        }
        return enchTip;
    }

    protected JSkyMod getActiveMod() {
        return ModManager.getInstance().getActiveMod();
    }

    protected final FinderByEdidFacade getFinder() {
        return FinderByEdidFacade.create();
    }

    protected LeveledEntryFactory getLeveledEntryFactory() {
        return LeveledEntryFactory.create();
    }

    protected FinderByFormId<Enchantment> getEntchantmentByFormIdFinder() {
        return FinderByFormIdFactory.create().createEnchantmentFinder();
    }
}
